import axios from "axios";

// eslint-disable-next-line no-unused-vars
const submitDetailedResult =async (rects,id,target) => {

    for (let i = 0; i < rects.length;i++){
        if (target.indexOf(rects[i].name) == -1){
            alert("请确认标签和要求的一样");
            location.reload();
            return ;
        }
    }

    const url = "/api/detailed-task/uploadResult?taskId="+id;
    // eslint-disable-next-line no-unused-vars
    const userId = sessionStorage.getItem("user.id");

    return new Promise((resolve, reject) => {
        axios.post(url, rects).then((response) => {
            console.log(response.data)
            if (response.data == true) {
                axios.get("/api/detailed-task/submit",{
                    params:{
                        taskId: id,
                        crowdId: userId
                    }
                }).then((response)=>{
                    if (response.data == false){
                        alert("用户不存在")

                    }else {
                        alert("提交成功")
                        location.reload();
                    }
                })

            } else {
                alert("提交失败")
                console.log(resolve);
                console.log(reject)
            }

        }).catch((reason) => {
            resolve = reason;
            alert("提交失败")
        })
    })

}

export default submitDetailedResult;